/**
 * @module 购物车
 */

import req from '@/utils/request.js';
import * as URL from '@/constants/api.js';

export function getCartList() {
  return req({
    url: URL.MEMBER_CART,
    method: 'GET',
  })
    .then((res) => {
      // return res.data.result;
      return {
        ...res,
        // 计算全部商品数
        allIn: res.data.result.reduce((prev, item) => {
          return item.count > 0 ? prev + item.count : prev + 0;
        }, 0),
      };
    })
    .catch(() => ({}));
}
